﻿/*******************************************************************************
 * Copyright @ 2017 YunSpace.Framework 版权所有
 * Author: GaoTang
 * Description: YunSpace 快速开发平台
 * Website：http://www.yunspace.com.cn
*********************************************************************************/
#region USING SYSTEM
using System.Collections.Generic;
using System.Linq;
using YunSpace.Data;
using YunSpace.Domain.Entity.MiniSite;
using YunSpace.Domain.IRepository.MiniSite;
#endregion

namespace YunSpace.Repository.MiniSite
{
    public class CommentRepository : RepositoryBase<SiteCommentEntity>, ICommentRepository
    {
        /// <summary>
        /// 精选场地
        /// 场地评论数量最多的五条记录
        /// </summary>
        public List<string> GetTop5SiteCommentMost()
        {
            // SELECT *
            //    FROM SL_Site site
            //    WHERE site.F_Id in (
            //        SELECT c.F_SiteId
            //        FROM MiniSite_Comment c
            //        LEFT JOIN MiniSite_CommentAndTagRelation ctr
            //        ON c.F_Id = ctr.F_CommentId
            //        WHERE c.F_OrderType = 1
            //        GROUP BY c.F_SiteId
            //        ORDER BY COUNT(c.F_SiteId) DESC
            //        LIMIT 0, 5
            //    )
            string sqlStr = @"SELECT c.F_SiteId
	                            FROM MiniSite_Comment c
	                            LEFT JOIN MiniSite_CommentAndTagRelation ctr
	                            ON c.F_Id = ctr.F_CommentId
	                            WHERE c.F_OrderType = 1
	                            GROUP BY c.F_SiteId
	                            ORDER BY COUNT(c.F_SiteId) DESC
	                            LIMIT 0, 5";

            //return FindList(sqlStr).Select(p => p.F_SiteId).ToList();
            return GetColumnList<string>(sqlStr);
        }
    }
}

